<template>
	<view>
		<u-cell-group>
			<view v-if="ischeck !== ''" class="">
				<u-cell v-if="ischeck" class="cell" title="修改支付密码" isLink @click="gopaypass"></u-cell>
				<u-cell v-if="!ischeck" class="cell" title="添加支付密码" isLink @click="gopaypass"></u-cell>
			</view>
			<text class="titleyin">
				绑定银行
			</text>
			<!-- <u-cell size="large" v-for="item in main" class="cell" :icon=item.bankIconLink :title=item.bankName>
				<text slot="value" @click="changeshow(item.id)" class="unbind">解绑</text>
			</u-cell> -->

			<view class="banklist" v-for="(item,index) in main">
				<view class="cardtop">
					<view class="cardtopleft">
						<image :src=item.bankIconLink mode=""></image>
					</view>
					<view class="cardtopright">{{item.bankName}}</view>
				</view>
				<view class="cardcenter">
					{{replaceStr(item.cardNumber)}}
				</view>
				<view class="cardbottom">
					<view @click="changeshow(item.id)" class="btn">
						解除绑定
					</view>
					<view @click="goedit(item.id)" class="btn">
						修改信息
					</view>
				</view>

			</view>


			<view @click="goadd" class="add_card">
				<image :src="src" mode=""></image>
				<view class="add">
					点击添加银行
				</view>
			</view>

		</u-cell-group>

		<u-modal @confirm="unband" @cancel="show=false" :showCancelButton="true" :show="show" :title="title"
			:content='content'></u-modal>
	</view>
</template>

<script>
	import {
		withdrawalabout,
		deletedBankCard,
		checkpass
	} from '@/api/mine'
	export default {
		data() {
			return {
				src: "../../static/tabsIcon/add2.png",
				main: [],
				show: false,
				title: '解绑确认',
				content: '确定要解绑该银行卡吗？',
				id: "",
				ischeck: '',
			}
		},
		onShow() {
			this.withdrawalabout();
			this.checkpass();
		},
		methods: {
			replaceStr(str) {
				return str.replace(/(.{4})/g, '$1    ');
			},
			checkpass() {
				checkpass().then(res => {
					this.ischeck = res.data;
				})
			},
			goedit(id) {
				uni.navigateTo({
					url: './editbankcard?id=' + id
				})
			},
			gopaypass() {
				if (this.ischeck) {
					uni.navigateTo({
						url: './resetpass'
					})
				} else {
					uni.navigateTo({
						url: './setpaypass'
					})
				}
			},
			changeshow(id) {
				this.show = true;
				this.id = id;
			},
			unband() {
				this.show = false;
				deletedBankCard(this.id).then(res => {
					if (res.success == 1) {
						uni.showToast({
							icon: 'none',
							title: '解绑成功!'
						})
						this.withdrawalabout();
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			withdrawalabout() {
				withdrawalabout().then(res => {
					if (res.success == 1) {
						this.main = res.data.bankCardList;
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			goadd() {
				uni.navigateTo({
					url: "./addcard"
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(229, 231, 233);
	}

	.cell {
		background-color: rgb(255, 255, 255);
		margin-bottom: 20rpx;
	}

	.titleyin {
		position: relative;
		padding-top: 100rpx;
		width: 93%;
		height: 80rpx;
		margin: 0 auto;
		left: 0;
		right: 0;
		line-height: 80rpx;
		font-weight: 600;
		// background-color: #1467FF;
	}

	.add_card {
		background: #FFFFFF;
		border-radius: 10px;
		display: flex;
		align-items: center;
		padding: 40rpx;

		image {
			width: 60rpx;
			height: 60rpx;
			margin-right: 40rpx;
		}

		.add {
			color: rgba(0, 0, 0, 0.8);
			font-size: 32rpx;
		}
	}

	.unbind {
		color: rgba(0, 0, 0, 0.5);
		font-size: 26rpx;
		border-radius: 20rpx;
		border: 2rpx solid rgba(0, 0, 0, 0.5);
		padding: 4rpx 15rpx;
	}

	.banklist {
		height: 300upx;
		width: 95%;
		// display: flex;
		// padding: 32upx 20upx;
		align-items: center;
		margin-bottom: 20upx;
		background-image: url("../../static/tabsIcon/club/clubbg.png");
		background-size: 100% 100%;
		margin: 20upx auto;
		border-radius: 20upx;

		.addbank {
			height: 172upx;
			line-height: 172upx;
			// margin-top: 70upx;
		}

		.cardtop {
			display: flex;
			align-items: center;

			.cardtopleft {
				image {
					height: 80upx;
					width: 80upx;
					background-color: #FFFFFF;
					border-radius: 999rem;
					margin-top: 40upx;
					margin-left: 40upx;
				}
			}

			.cardtopright {
				margin-top: 40upx;
				margin-left: 40upx;
				color: #FFFFFF;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
			}
		}

		.cardcenter {
			margin: 20upx auto;
			width: 90%;
			text-align: center;
			color: #FFFFFF;
			// background-color: #007AFF;
		}

		.cardbottom {
			display: flex;
			justify-content: space-around;
			color: #FFFFFF;
		}

		.btn {
			width: 180rpx;
			height: 50rpx;
			line-height: 50rpx;
			border: 2rpx solid #FFFFFF;
			text-align: center;
			border-radius: 20rpx;
		}
	}
</style>
